package _99练习;

import javax.swing.*;
import java.awt.*;
import java.text.SimpleDateFormat;
import java.util.Calendar;

<<<<<<< HEAD
/**
 * @author ZhiCheng Qian
 * @since 2021/11/30 13:09
 */
=======

>>>>>>> 1c69d32fc055e0010098b09f71795769d9a12acd
public class Clock extends JFrame implements Runnable {

	static JLabel time;

	public Clock() {
		this.setLayout(null);
		time = new JLabel();
		time.setBounds(100, 70, 200, 80);
		Font font = new Font("微软雅黑", Font.PLAIN, 18);
		time.setFont(font);
		this.add(time);
	}

	@Override
	public void run() {
		while (true) {
			time.setText(getTime());

			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

	public String getTime() {
		Calendar calendar = Calendar.getInstance();
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String currentTime = formatter.format(calendar.getTime());
		return currentTime;
	}

}
